package net.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 	服务器
 * @author Administrator
 *
 */
public class TCPServer {

	
	public static void main(String[] args) throws IOException {
		// 创建服务器
		ServerSocket server = new ServerSocket(8888);
		
		// 等待链接
		System.out.println("服务器已启动，等待链接");
		Socket socket = server.accept();
		System.out.println("有一个用户链接");
		
		// 获取数据
		InputStream in = socket.getInputStream();
		byte[] content = new byte[1024];
		int length = in.read(content);
		while(length != -1) {
			System.out.println("获取到的数据是：" + new String(content, 0, length));
			length = in.read(content);
		}
		
		// 关闭资源
		in.close();
		socket.close();
		server.close();
	}
	
}
